package com.ruoyi.system.service.carte.server.impl;

import com.ruoyi.system.domain.XxkCarte;
import com.ruoyi.system.domain.request.BaseTransRequest;
import com.ruoyi.system.domain.request.CarteStatusRequest;
import com.ruoyi.system.service.carte.AbstractCarteService;
import com.ruoyi.system.service.carte.CarteConst;
import com.ruoyi.system.service.carte.server.ICarteStatus;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Service
public class CarteStatusImpl extends AbstractCarteService implements ICarteStatus {
    @Override
    public String status(CarteStatusRequest transRequest) {
        try{
            return commonHandle(transRequest);
        }catch (Exception e) {
            log.error(e.getMessage(),e);
            return e.getMessage();
        }
//        return "error";
    }

    public  void setRequestUrl(XxkCarte xxkCarte, BaseTransRequest baseTransRequest ) throws Exception {
        CarteStatusRequest transRequest =(CarteStatusRequest)baseTransRequest;
        if(StringUtils.isBlank(transRequest.getXml())){
            transRequest.setXml("N");
        }
        String url = "http://" + xxkCarte.getCarteIp() + ":" + xxkCarte.getCartePort()+ CarteConst.CARTE_STATUS_SUFFIXPATH;
        url = url.replace( " ", "%20" );

        transRequest.setRequestUrl(url);

        Map<String,Object> param=new HashMap<>();
        if(!StringUtils.isBlank(transRequest.getXml())){
            param.put("xml",transRequest.getXml());
        }
        transRequest.setParmMap(param);
    }
}
